package com.wenbo.fish.entity;

import com.wenbo.fish.enums.SpiderServiceEnum;
import com.wenbo.fish.utils.GsonUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;

import java.util.HashMap;
import java.util.Map;

/**
 * @author changwenbo
 * @date 2024/12/31 14:01
 */
@Data
@Slf4j
public class CookieConstant implements ApplicationListener<ApplicationReadyEvent> {
    private String zhihu;
    private String baidu;
    private String weibo;
    private String toutiao;
    private String tieba;

    private Map<SpiderServiceEnum, String> cookieMap = new HashMap<>();


    public String getCookie(SpiderServiceEnum spiderServiceEnum) {
        return cookieMap.get(spiderServiceEnum);
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        cookieMap.put(SpiderServiceEnum.ZHI_HU, getZhihu());
        cookieMap.put(SpiderServiceEnum.BAI_DU, baidu);
        cookieMap.put(SpiderServiceEnum.WEI_BO, weibo);
        cookieMap.put(SpiderServiceEnum.TOU_TIAO, toutiao);
        cookieMap.put(SpiderServiceEnum.TIE_BA, tieba);

        log.info("cookieMap = {}", GsonUtils.toJson(cookieMap));
    }
}
